package com.spider.admin.scaffold.controller;

import com.spider.admin.scaffold.service.LoginService;
import com.spider.admin.scaffold.common.Result;
import com.spider.admin.scaffold.common.annotation.OperationAspect;
import com.spider.admin.scaffold.service.TokenBlacklistService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.oauth2.provider.token.ConsumerTokenServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.web.bind.annotation.*;


/**
 * @author xiong.bo
 * @version 1.0
 * @date 2020/10/31 19:02
 */
@Tag(name = "登录")
@RestController
@RequestMapping("/admin")
public class LoginController {

    @Autowired
    private TokenBlacklistService tokenBlacklistService;


    /**
     * 用户退出
     *
     * @param accessToken
     * @return
     */
    @Operation(summary = "用户退出")
    @PostMapping("/logout")
    @OperationAspect(accessPath = "/logout", accessDesc = "用户退出")
    public Result<Boolean> logout(@RequestParam(name = "token") String accessToken) {

        // 由于使用的JwtTokenStore,自定义token过期机制
        tokenBlacklistService.addToBlacklist(accessToken);

        return Result.of(true);
    }


    /**
     * 获取token调用接口
     * 步骤：
     * 1，localhost:8080/api/oauth/token  Post请求
     * 2，Auth选择Basic Auth,
     *      username填AuthorizationServerConfiguration配置的clientId，
     *      password填AuthorizationServerConfiguration配置的secret
     * 3，body输入x-www-form-unlencoded格式，
     *      grant_type:password
     *      username:tom
     *      password:123456
     * 4，token是接口返回的access_token值
     * 5，token放到Auth的Bearer Token中
     */
}
